package cn.belong.jk.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.belong.jk.entity.ContractProduct;
import cn.belong.jk.entity.Factory;
import cn.belong.jk.service.ContractProductService;
import cn.belong.jk.service.FactoryService;

@Controller  
@RequestMapping("contractProduct")
public class ContractProductController extends BaseController{  
      
		@Resource
	    ContractProductService contractProductService;   
		@Resource
	    FactoryService factoryService;  
	      
	  //转向新增页面  
	    @RequestMapping("/tocreate.action")  
	    public String tocreate(String contractId,Model model){  
	        //传递购销合同Id  
	        model.addAttribute("contractId", contractId);  
	          
	        //准备生产厂家的下拉列表  
	        List<Factory> factoryList=factoryService.getFactoryList();  
	        model.addAttribute("factoryList",factoryList);  
	          
	        //某个合同下的货物  
	        Map paraMap=new HashMap();  
	        paraMap.put("contractId", contractId);  
	        List<ContractProduct> dataList=contractProductService.find(paraMap);  
	        model.addAttribute("dataList", dataList);  
	          
	        return "/cargo/contract/jContractProductCreate.jsp";//货物的新增页面  
	    }  
	      
	    //新增  
	    @RequestMapping("/insert.action")  
	    public String insert(ContractProduct contractProduct,Model model){  
	        contractProductService.insert(contractProduct);  
	          
	        model.addAttribute("contractId", contractProduct.getContractId());  
	          
	        return "redirect:/contractProduct/tocreate.action";  
	    }  
	    
	  //转向修改页面  
	    @RequestMapping("/toupdate.action")  
	    public String toupdate(String id,Model model){  
	        ContractProduct obj=contractProductService.get(id);  
	        model.addAttribute("obj", obj);  
	          
	        //准备生产厂家的下拉列表  
	        List<Factory> factoryList=factoryService.getFactoryList();  
	        model.addAttribute("factoryList",factoryList);  
	          
	        return "/cargo/contract/jContractProductUpdate.jsp";//货物的修改页面  
	    }  
	      
	      
	    //修改  
	    @RequestMapping("/update.action")  
	    public String toupdate(ContractProduct contractProduct,Model model){  
	        contractProductService.update(contractProduct);  
	          
	        model.addAttribute("contractId", contractProduct.getContractId());  
	          
	        return "redirect:/contractProduct/tocreate.action";  
	    }  
	    
	  //删除  
	    @RequestMapping("/delete.action")  
	    public String delete(String contractId,String id,Model model){  
	        contractProductService.deleteById(id);  
	              
	        model.addAttribute("contractId", contractId);  
	              
	        return "redirect:/contractProduct/tocreate.action";  
	    }  
}  
